<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>vuepress-plugin-table-of-contents | VuePress Community</title>
    <meta name="generator" content="VuePress 1.4.1">
    <link rel="icon" href="/logo/600x600.png">
    <meta name="description" content="Community supported ecosystem for VuePress">
    <meta name="theme-color" content="#3eaf7c">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="msapplication-TileColor" content="#000000">
    <link rel="preload" href="/assets/css/0.styles.6c0c5975.css" as="style"><link rel="preload" href="/assets/js/app.642d23b3.js" as="script"><link rel="preload" href="/assets/js/40.20d66e6f.js" as="script"><link rel="preload" href="/assets/js/page-f3f5674c.c5689d98.js" as="script"><link rel="preload" href="/assets/js/42.2c37f203.js" as="script"><link rel="prefetch" href="/assets/js/41.3a1d8c85.js"><link rel="prefetch" href="/assets/js/43.6ef7f18f.js"><link rel="prefetch" href="/assets/js/44.b27fbcf7.js"><link rel="prefetch" href="/assets/js/45.c3252ceb.js"><link rel="prefetch" href="/assets/js/46.9c844637.js"><link rel="prefetch" href="/assets/js/page-07d1601e.242c2d2a.js"><link rel="prefetch" href="/assets/js/page-07f51dda.32726b1b.js"><link rel="prefetch" href="/assets/js/page-0a6678e5.628ba2fc.js"><link rel="prefetch" href="/assets/js/page-0f8f6766.b84a099f.js"><link rel="prefetch" href="/assets/js/page-1204fa10.e7865c5b.js"><link rel="prefetch" href="/assets/js/page-12e4fd46.7452ae30.js"><link rel="prefetch" href="/assets/js/page-14660f14.f5838285.js"><link rel="prefetch" href="/assets/js/page-17a68826.0f6f2110.js"><link rel="prefetch" href="/assets/js/page-1982deb4.01bbc28c.js"><link rel="prefetch" href="/assets/js/page-216dd7c6.119f4c59.js"><link rel="prefetch" href="/assets/js/page-2d1fe5d8.ab8c6d4c.js"><link rel="prefetch" href="/assets/js/page-33083986.2f59b20d.js"><link rel="prefetch" href="/assets/js/page-353b8594.d79d4319.js"><link rel="prefetch" href="/assets/js/page-36ce40ea.66f2730d.js"><link rel="prefetch" href="/assets/js/page-3b6ebfa4.df1831eb.js"><link rel="prefetch" href="/assets/js/page-3e5179ee.f0d7043f.js"><link rel="prefetch" href="/assets/js/page-42f1e69c.ad94d467.js"><link rel="prefetch" href="/assets/js/page-4336d0c6.a4013cdd.js"><link rel="prefetch" href="/assets/js/page-4362efe0.40a6a106.js"><link rel="prefetch" href="/assets/js/page-4d80adb0.c788d5af.js"><link rel="prefetch" href="/assets/js/page-4eab9ae2.3c07cca2.js"><link rel="prefetch" href="/assets/js/page-5170c35e.ba839aac.js"><link rel="prefetch" href="/assets/js/page-55154126.4114c7df.js"><link rel="prefetch" href="/assets/js/page-5b4049d8.28b01370.js"><link rel="prefetch" href="/assets/js/page-5c13450a.559f8c58.js"><link rel="prefetch" href="/assets/js/page-5e11724a.743dcab4.js"><link rel="prefetch" href="/assets/js/page-6aa1c294.d5c24ca3.js"><link rel="prefetch" href="/assets/js/page-6aa62140.570cd351.js"><link rel="prefetch" href="/assets/js/page-6c372be6.1768c8fc.js"><link rel="prefetch" href="/assets/js/page-6c6f6eb8.55332c8a.js"><link rel="prefetch" href="/assets/js/page-70397cc5.38298d74.js"><link rel="prefetch" href="/assets/js/page-7a8d5874.bebc26b5.js"><link rel="prefetch" href="/assets/js/page-7bec420c.42c63b19.js"><link rel="prefetch" href="/assets/js/page-8ed296e4.ee2655fc.js"><link rel="prefetch" href="/assets/js/page-c3486808.466685fd.js"><link rel="prefetch" href="/assets/js/page-c9903bc8.3b89aecd.js"><link rel="prefetch" href="/assets/js/page-e2b999b4.9e2fd49d.js">
    <link rel="stylesheet" href="/assets/css/0.styles.6c0c5975.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/en/" class="home-link router-link-active"><!----> <span class="site-name">VuePress Community</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Select language" class="dropdown-title"><span class="title">Languages</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/en/plugins/table-of-contents/" class="nav-link router-link-exact-active router-link-active">
  English
</a></li><li class="dropdown-item"><!----> <a href="/zh/plugins/table-of-contents/" class="nav-link">
  简体中文
</a></li></ul></div></div> <a href="https://github.com/vuepress/vuepress-community" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Select language" class="dropdown-title"><span class="title">Languages</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/en/plugins/table-of-contents/" class="nav-link router-link-exact-active router-link-active">
  English
</a></li><li class="dropdown-item"><!----> <a href="/zh/plugins/table-of-contents/" class="nav-link">
  简体中文
</a></li></ul></div></div> <a href="https://github.com/vuepress/vuepress-community" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></nav>  <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>Plugins</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/en/plugins/clean-urls/" class="sidebar-link">vuepress-plugin-clean-urls</a></li><li><a href="/en/plugins/container/" class="sidebar-link">vuepress-plugin-container</a></li><li><a href="/en/plugins/copyright/" class="sidebar-link">vuepress-plugin-copyright</a></li><li><a href="/en/plugins/dehydrate/" class="sidebar-link">vuepress-plugin-dehydrate</a></li><li><a href="/en/plugins/git-log/" class="sidebar-link">vuepress-plugin-git-log</a></li><li><a href="/en/plugins/mathjax/" class="sidebar-link">vuepress-plugin-mathjax</a></li><li><a href="/en/plugins/medium-zoom/" class="sidebar-link">vuepress-plugin-medium-zoom</a></li><li><a href="/en/plugins/migrate/" class="sidebar-link">vuepress-plugin-migrate</a></li><li><a href="/en/plugins/named-chunks/" class="sidebar-link">vuepress-plugin-named-chunks</a></li><li><a href="/en/plugins/nprogress/" class="sidebar-link">vuepress-plugin-nprogress</a></li><li><a href="/en/plugins/redirect/" class="sidebar-link">vuepress-plugin-redirect</a></li><li><a href="/en/plugins/serve/" class="sidebar-link">vuepress-plugin-serve</a></li><li><a href="/en/plugins/smooth-scroll/" class="sidebar-link">vuepress-plugin-smooth-scroll</a></li><li><a href="/en/plugins/table-of-contents/" class="active sidebar-link">vuepress-plugin-table-of-contents</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/en/plugins/table-of-contents/#installation" class="sidebar-link">Installation</a></li><li class="sidebar-sub-header"><a href="/en/plugins/table-of-contents/#usage" class="sidebar-link">Usage</a></li><li class="sidebar-sub-header"><a href="/en/plugins/table-of-contents/#configs" class="sidebar-link">Configs</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/en/plugins/table-of-contents/#componentname" class="sidebar-link">componentName</a></li></ul></li><li class="sidebar-sub-header"><a href="/en/plugins/table-of-contents/#component-props" class="sidebar-link">Component Props</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/en/plugins/table-of-contents/#includelevel" class="sidebar-link">includeLevel</a></li></ul></li><li class="sidebar-sub-header"><a href="/en/plugins/table-of-contents/#demo" class="sidebar-link">Demo</a></li><li class="sidebar-sub-header"><a href="/en/plugins/table-of-contents/#differences-from-vuepress-markdown-toc-syntax" class="sidebar-link">Differences from VuePress markdown toc syntax</a></li></ul></li><li><a href="/en/plugins/typescript/" class="sidebar-link">vuepress-plugin-typescript</a></li><li><a href="/en/plugins/zooming/" class="sidebar-link">vuepress-plugin-zooming</a></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Tools</span> <span class="arrow right"></span></p> <!----></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="vuepress-plugin-table-of-contents"><a href="#vuepress-plugin-table-of-contents" class="header-anchor">#</a> vuepress-plugin-table-of-contents <a rel="noopener noreferrer" target="_blank" title="vuepress/vuepress-community" href="https://github.com/vuepress/vuepress-community" class="github-link"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 28 28"><path d="M14 0C6.27 0 0 6.43 0 14.36c0 6.34 4.01 11.72 9.57 13.62.7.13.96-.31.96-.69 0-.34-.01-1.24-.02-2.44-3.89.87-4.72-1.92-4.72-1.92-.64-1.66-1.55-2.1-1.55-2.1-1.27-.89.1-.87.1-.87 1.4.1 2.14 1.48 2.14 1.48 1.25 2.19 3.28 1.56 4.07 1.19.13-.93.49-1.56.89-1.92-3.11-.36-6.38-1.59-6.38-7.09 0-1.57.55-2.85 1.44-3.85-.14-.36-.62-1.82.14-3.8 0 0 1.18-.39 3.85 1.47a12.8 12.8 0 0 1 3.5-.48c1.19.01 2.39.16 3.5.48 2.67-1.86 3.85-1.47 3.85-1.47.76 1.98.28 3.44.14 3.8.9 1 1.44 2.28 1.44 3.85 0 5.51-3.27 6.73-6.39 7.08.5.44.95 1.32.95 2.66 0 1.92-.02 3.47-.02 3.94 0 .38.25.83.96.69C23.99 26.07 28 20.7 28 14.36 28 6.43 21.73 0 14 0z" fill-rule="evenodd" clip-rule="evenodd"></path></svg></a></h1> <p>Add table-of-contents component for your VuePress site.</p> <h2 id="installation"><a href="#installation" class="header-anchor">#</a> Installation</h2> <div class="language-sh extra-class"><pre class="language-sh"><code><span class="token function">npm</span> <span class="token function">install</span> -D vuepress-plugin-table-of-contents
</code></pre></div><h2 id="usage"><a href="#usage" class="header-anchor">#</a> Usage</h2> <div class="language-js extra-class"><pre class="language-js"><code><span class="token comment">// .vuepress/config.js</span>
module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token punctuation">{</span>
  plugins<span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">'vuepress-plugin-table-of-contents'</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span>
</code></pre></div><p>This plugin will register a <code>&lt;TOC /&gt;</code> component for you, which will render the table-of-contents of current page. You can use it in your markdown and vue files.</p> <div class="language-md extra-class"><pre class="language-md"><code><span class="token comment">&lt;!-- README.md / Component.vue --&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>TOC</span> <span class="token punctuation">/&gt;</span></span>
</code></pre></div><h2 id="configs"><a href="#configs" class="header-anchor">#</a> Configs</h2> <h3 id="componentname"><a href="#componentname" class="header-anchor">#</a> componentName</h3> <ul><li><strong>type:</strong> <code>string</code></li> <li><strong>default:</strong> <code>'TOC'</code></li></ul> <p>Name of the table-of-contents component.</p> <h2 id="component-props"><a href="#component-props" class="header-anchor">#</a> Component Props</h2> <h3 id="includelevel"><a href="#includelevel" class="header-anchor">#</a> includeLevel</h3> <ul><li><strong>type:</strong> <code>[number, number]</code></li> <li><strong>default:</strong> <code>[2, 3]</code></li></ul> <p>The level of title to be included in <code>&lt;TOC /&gt;</code> component.</p> <p>For example, <code>[2, 4]</code> means 2 &lt;= x &lt;= 4.</p> <h2 id="demo"><a href="#demo" class="header-anchor">#</a> Demo</h2> <p><strong>Input</strong></p> <div class="language-md extra-class"><pre class="language-md"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>TOC</span> <span class="token punctuation">/&gt;</span></span>
</code></pre></div><p><strong>Output</strong></p> <div><ul><li><a href="/en/plugins/table-of-contents/#installation">Installation</a></li><li><a href="/en/plugins/table-of-contents/#usage">Usage</a></li><li><a href="/en/plugins/table-of-contents/#configs">Configs</a><ul><li><a href="/en/plugins/table-of-contents/#componentname">componentName</a></li></ul></li><li><a href="/en/plugins/table-of-contents/#component-props">Component Props</a><ul><li><a href="/en/plugins/table-of-contents/#includelevel">includeLevel</a></li></ul></li><li><a href="/en/plugins/table-of-contents/#demo">Demo</a></li><li><a href="/en/plugins/table-of-contents/#differences-from-vuepress-markdown-toc-syntax">Differences from VuePress markdown toc syntax</a></li></ul></div> <p><strong>Input</strong></p> <div class="language-md extra-class"><pre class="language-md"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>TOC</span> <span class="token attr-name">:include-level</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>[2, 2]<span class="token punctuation">&quot;</span></span> <span class="token punctuation">/&gt;</span></span>
</code></pre></div><p><strong>Output</strong></p> <div><ul><li><a href="/en/plugins/table-of-contents/#installation">Installation</a></li><li><a href="/en/plugins/table-of-contents/#usage">Usage</a></li><li><a href="/en/plugins/table-of-contents/#configs">Configs</a></li><li><a href="/en/plugins/table-of-contents/#component-props">Component Props</a></li><li><a href="/en/plugins/table-of-contents/#demo">Demo</a></li><li><a href="/en/plugins/table-of-contents/#differences-from-vuepress-markdown-toc-syntax">Differences from VuePress markdown toc syntax</a></li></ul></div> <h2 id="differences-from-vuepress-markdown-toc-syntax"><a href="#differences-from-vuepress-markdown-toc-syntax" class="header-anchor">#</a> Differences from VuePress markdown toc syntax</h2> <p>You may notice that VuePress also provides a <a href="https://vuepress.vuejs.org/guide/markdown.html#table-of-contents" target="_blank" rel="noopener noreferrer">markdown syntax <code>[[toc]]</code><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a> for table-of-contents.</p> <p>However, <code>[[toc]]</code> can only be used in <code>.md</code> files as it's a markdown syntax. But <code>&lt;TOC /&gt;</code> can be used in both <code>.md</code> files and <code>.vue</code> files, as it's a Vue component.</p> <p>Thus, <code>&lt;TOC /&gt;</code> is more convenient if you need table-of-contents in other part of your VuePress site (e.g. build your own theme with a table-of-contents component).</p></div> <footer class="page-edit"><div class="edit-link"><a href="https://github.com/vuepress/vuepress-community/edit/master/packages/docs/src/en/plugins/table-of-contents.md" target="_blank" rel="noopener noreferrer">Edit this page on GitHub</a> <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></div> <div class="last-updated"><span class="prefix">Last Updated:</span> <span class="time">5/6/2020, 3:40:32 AM</span></div></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/en/plugins/smooth-scroll/" class="prev">
        vuepress-plugin-smooth-scroll
      </a></span> <span class="next"><a href="/en/plugins/typescript/">
        vuepress-plugin-typescript
      </a>
      →
    </span></p></div> </main></div><div class="global-ui"><!----></div></div>
    <script src="/assets/js/app.642d23b3.js" defer></script><script src="/assets/js/40.20d66e6f.js" defer></script><script src="/assets/js/page-f3f5674c.c5689d98.js" defer></script><script src="/assets/js/42.2c37f203.js" defer></script>
  </body>
</html>
